import { defineStore } from 'pinia'
import { asyncRoutes, router, routes } from '@/router'

export const usePermissionStore = defineStore('permission', {
  state: () => ({
    isLogin: Boolean(localStorage.getItem('isLogin')),
    hasRoutes: false,
    menus: <any>[]
    // menus: [] as any
  }),
  actions: {
    setLogin() {
      localStorage.setItem('isLogin', 'true')
      this.isLogin = true
      asyncRoutes.forEach(route => {
        router.options.routes.push(route)
        router.addRoute(route)
      })
      this.hasRoutes = true
      this.menus = asyncRoutes
    }
  }
})
